package com.tianji.learning.controller;


import com.baomidou.mybatisplus.extension.plugins.pagination.PageDto;
import com.tianji.common.domain.dto.PageDTO;
import com.tianji.learning.domain.dto.QuestionFormDTO;
import com.tianji.learning.domain.query.QuestionPageQuery;
import com.tianji.learning.domain.vo.QuestionVO;
import com.tianji.learning.service.InteractionQuestionService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.RequiredArgsConstructor;
import org.apache.ibatis.annotations.Delete;
import org.checkerframework.checker.units.qual.A;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;

/**
 * <p>
 * 互动提问的问题表 前端控制器
 * </p>
 *
 * @author 蒼飞
 * @since 2023-09-04
 */
@RestController
@RequiredArgsConstructor
@Api("互动问答相关接口")
@RequestMapping("/questions")
public class InteractionQuestionController {

    private final InteractionQuestionService interactionQuestionService;
    @ApiOperation("新增互动问题")
    @PostMapping
    public void saveQuestion(@Valid @RequestBody QuestionFormDTO questionFormDTO){
        interactionQuestionService.saveQuestion(questionFormDTO);
    }

    @ApiOperation("修改互动问题")
    @PutMapping("/{id}")
    public void updateQuestion(@Valid @RequestBody QuestionFormDTO questionFormDTO, @PathVariable Long id){
        interactionQuestionService.updateQuestion(id,questionFormDTO);
    }

    @ApiOperation("分页查询互动问题")
    @GetMapping("/page")
    public PageDTO<QuestionVO> queryQuestionPage(QuestionPageQuery questionPageQuery){
        return interactionQuestionService.queryQuestionPage(questionPageQuery);
    }
    @ApiOperation("根据id查询问题详情")
    @GetMapping("/{id}")
    public QuestionVO queryQuestionById(@ApiParam(value = "问题id", example = "1") @PathVariable("id") Long id){
        return interactionQuestionService.queryQuestionById(id);
    }

    @ApiOperation("删除互动问题")
    @DeleteMapping("/{id}")
    public void deleteQuestion(@PathVariable("id") Long id){
        interactionQuestionService.deleteQuestion(id);
    }
}
